package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbRepairtypeVo;
import com.ruoyi.tb.lmt.domain.bo.TbRepairtypeBo;
import com.ruoyi.tb.lmt.service.ITbRepairtypeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检修类型
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/repairtype")
public class TbRepairtypeController extends BaseController {

    private final ITbRepairtypeService iTbRepairtypeService;

    /**
     * 查询检修类型列表
     */
    @SaCheckPermission("xha-lmt:repairtype:list")
    @GetMapping("/list")
    public TableDataInfo<TbRepairtypeVo> list(TbRepairtypeBo bo, PageQuery pageQuery) {
        return iTbRepairtypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出检修类型列表
     */
    @SaCheckPermission("xha-lmt:repairtype:export")
    @Log(title = "检修类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbRepairtypeBo bo, HttpServletResponse response) {
        List<TbRepairtypeVo> list = iTbRepairtypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "检修类型", TbRepairtypeVo.class, response);
    }

    /**
     * 获取检修类型详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("xha-lmt:repairtype:query")
    @GetMapping("/{ID}")
    public R<TbRepairtypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbRepairtypeService.queryById(ID));
    }

    /**
     * 新增检修类型
     */
    @SaCheckPermission("xha-lmt:repairtype:add")
    @Log(title = "检修类型", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbRepairtypeBo bo) {
        return toAjax(iTbRepairtypeService.insertByBo(bo));
    }

    /**
     * 修改检修类型
     */
    @SaCheckPermission("xha-lmt:repairtype:edit")
    @Log(title = "检修类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbRepairtypeBo bo) {
        return toAjax(iTbRepairtypeService.updateByBo(bo));
    }

    /**
     * 删除检修类型
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("xha-lmt:repairtype:remove")
    @Log(title = "检修类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbRepairtypeService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }
}
